﻿using MediatR;
using SlaughterItem.Common.Domains.Setup;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.LiveAnimalsa
{
    public class WaitingsSelectShowHandler : IRequestHandler<WaitingsSelectShowCommand, Result>
    {
        IBaseRepositoryGet<Waitings> WaitingsRep;

        public WaitingsSelectShowHandler(IBaseRepositoryGet<Waitings> waitingsRep)
        {
            WaitingsRep = waitingsRep;
        }
        /// <summary>
        /// 待宰圈下拉框绑定
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(WaitingsSelectShowCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var list = from a in WaitingsRep.GetAll()
                           select new
                           {
                               a.WaitingId,
                               a.WaitingName
                           };
                if (list.Count() > 0)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = list;
                    result.Msg = "成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
